package com.lzz.bottomencapsulation.customview.selectimage.viewholder;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.lzz.bottomencapsulation.R;
import com.lzz.bottomencapsulation.customview.selectimage.ImageConfig;
import com.lzz.bottomencapsulation.customview.selectimage.bean.Image;
import com.lzz.bottomencapsulation.holder.MvpRVViewHolder;

import java.util.List;


/**
 * Created by apple on 17/6/8.
 */

public class Item_image extends MvpRVViewHolder<Image> {
    ImageView photo_image;
    View photo_mask;
    ImageView photo_check;
    boolean showSelectIndicator;
    List<Image> selectedImageList;
    ImageConfig imageConfig;

    public void setSelectedImageList(List<Image> selectedImageList) {
        this.selectedImageList = selectedImageList;
    }

    public Item_image(Context context, boolean showSelectIndicator, ImageConfig imageConfig) {
        super(R.layout.imageselector_item_image, context);
        this.showSelectIndicator = showSelectIndicator;
        this.imageConfig = imageConfig;
        photo_image = (ImageView) itemView.findViewById(R.id.photo_image);
        photo_mask = itemView.findViewById(R.id.photo_mask);
        photo_check = (ImageView) itemView.findViewById(R.id.photo_check);
        photo_check.setOnClickListener(onClickListener);
    }

    @Override
    public void initView() {
        if (showSelectIndicator) {
            photo_check.setVisibility(View.VISIBLE);
            if (selectedImageList.contains(viewData)) {
                photo_check.setImageResource(R.mipmap.icon_select);
                photo_mask.setVisibility(View.VISIBLE);
            } else {
                photo_check.setImageResource(R.mipmap.icon_unselect);
                photo_mask.setVisibility(View.GONE);
            }
        } else {
            photo_check.setVisibility(View.GONE);
        }

        imageConfig.getImageLoader().displayImage((Activity) context, viewData.path, photo_image);
    }

}
